package com.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.dao.*;
import com.entity.Admin;
import com.impl.Dbutils;


public class AdmindaoImpl extends Basedao implements Admindao
{
	public int insertAdmin(Admin admin)
	{
		int result=0;
		String sql="insert into admin(username,password,realname) values(?,?,?)";
		Object[] values = {admin.getUsername(),admin.getPassword(),
				admin.getRealname()};
		Connection conn=Dbutils.createConn();
		super.executeUpdate(conn, sql, values);
		try
		{
		conn.close();	
		} 
		catch (SQLException e)
		{
		e.printStackTrace();
			// TODO: handle exception
		}
		return result;
	}
	public Admin selectbyAdmin(String username)
	{
		Admin admin=null;
		String sql="select * from admin where username=?";
		Object[] values= {username};
		Connection conn=Dbutils.createConn();
		ResultSet rs=super.executeQuery(conn, sql, values);
		try 
		{
		if(rs.next())	
		{
			admin=new Admin();
			admin.setUsername(rs.getString("username"));
			admin.setPassword(rs.getString("password"));
			admin.setRealname(rs.getString("realname"));
		
		}
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		return admin;
	}
}
